import sys
from random import choice
from time import sleep

free = True


class Animal:
    def __init__(self, name, sex, color):
        self.name = name
        self.sex = sex
        self.color = color

    def eat(self, eat_thing):
        global free
        free = False
        self.eat_thing = eat_thing
        return self.name + f"在吃{eat_thing}...\n"

    def poop(self):
        global free
        free = False
        return self.name + "在拉屎...\n"

    def sleeping(self, time: int):
        global free
        free = False
        self.time = time
        while self.time > 0:
            print(self.name + "睡觉中...")
            sleep(1.0)
            self.time -= 1
            if self.time == 0:
                return self.name + "睡醒啦 ~\n"


class CuteCat(Animal):
    def grab_sofa(self):
        global free
        free = False
        return self.name + "在抓沙发!!!"


# 创建实体
print("欢迎使用可爱猫猫系统 v0.1 作者：啊波呲")
select1 = input("\n请选择你要执行的操作：\n[1]创建一只可爱猫猫\n[2]创建一个人类\n输入一个数字吧：")
if select1 == "1":
    cat = CuteCat(
        name=input("\n请输入小猫的名字："), sex=input("请输入小猫的性别："), color=input("请输入小猫的花色：")
    )
    print(f"\n猫猫：你好，我是一只{cat.color}的{cat.sex}小猫，我叫{cat.name}")
elif select1 == "2":
    print("施工中，请之后再来创建人类")
else:
    print("不在可选范围内，请重新启动程序")
    sys.exit()

# 可爱猫猫
eat = 1
if select1 == "1":
    while True:
        while free:
            sleep(0.4)
            select2 = input(
                "\n请选择你要执行的操作：\n[1]让猫猫吃饭\n[2]让猫猫拉屎\n[3]让猫猫睡觉\n[4]不管它\n[5]退出程序吧\n输入一个数字吧："
            )
            if select2 == "1":
                eat_thing = input(f"\n你要给{cat.name}吃什么呢：")
                print(cat.eat(eat_thing))
                free = True
            elif select2 == "2":
                print(cat.poop())
                free = True
            elif select2 == "3":
                try:
                    sleep_time = int(input(f"\n你希望{cat.name}睡多久呢（秒）："))
                    print(cat.sleeping(sleep_time))
                except ValueError:
                    print("请输入一个整数!!")
                free = True
            elif select2 == "4":
                select3 = choice([1, 2])

                if select3 == 1:
                    print(f"\n{cat.name}很老实的坐在你旁边...")
                    sleep(0.5)
                    free = True
                if select3 == 2:
                    print("\n" + cat.grab_sofa())
                    free = True
            elif select2 == "5":
                print("我走啦,再见!")
                sleep(0.2)
                sys.exit()
            else:
                print("不在可选范围内")
                free = True
